package com.yangxk.kadmin.common.util;

import java.io.File;

/**
 * 系统路径工具类
 *
 * @author yangxk
 * @date 2018/9/13 11:35
 */
public class SystemPath {
    private SystemPath(){}

    /**
     * 获取项目根路径
     * create by yangxk on 2018/9/13 11:37
     */
    public static String getRootPath() {
        String classpath = SystemPath.class.getResource("/").getPath();
        File file = new File(classpath);
        return file.getParentFile().getParentFile().getAbsolutePath();
    }

    /**
     * 获取相对于根路径的绝对路径
     * create by yangxk on 2018/9/13 11:38
     */
    public static String getPathRelativeRoot(String relativePath) {
        if (relativePath == null || relativePath.isEmpty())
            return relativePath;

        if (relativePath.startsWith("/"))
            return getRootPath() + relativePath;

        return getRootPath() + File.separator + relativePath;
    }

    /**
     * 获取maven项目的 src/main/java路径
     * create by yangxk on 2018/9/13 11:39
     */
    public static String getMavenSrcPath() {
        return getPathRelativeRoot("src/main/java");
    }
}
